/**
 * 收费管理
 */
<template>
  <div>
    
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column sortable prop="rid" label="序号" width="80">
      </el-table-column>
      <el-table-column sortable prop="pname" label="患者姓名" width="100">
      </el-table-column>
      <el-table-column sortable prop="psex" label="患者性别" width="100">
      </el-table-column>
      <el-table-column sortable prop="page" label="患者年龄" width="100">
      </el-table-column>
      <el-table-column sortable prop="phoneNumber" label="联系方式" width="120">
      </el-table-column>
      <el-table-column sortable prop="office" label="科室" width="80">
      </el-table-column>
      <el-table-column sortable prop="doctorName" label="接诊医生" width="100">
      </el-table-column>
      <el-table-column sortable prop="registrationFee" label="挂号费（元）" width="120">
      </el-table-column>
      <el-table-column sortable prop="reChargeStatusLabel" label="挂号收费状态" width="120">
      </el-table-column>
      
      <el-table-column sortable prop="prescriptionFee" label="处方开立收费（元）" width="160">
        <template slot-scope="scope">
          <!--将查到的价格(单位:分)转换单位(元)进行显示-->
          <div>{{ scope.row.prescriptionFee / 100 }}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="prChargeStatusLabel" label="处方开立收费状态" min-width="150">
      </el-table-column>

      
    </el-table>
    <!-- 分页组件 -->
    
    <!-- 挂号费支付弹框 -->
    <el-dialog title="挂号费支付" :visible.sync="editFormVisible" width="681px" @click="closeDialog">
      <el-container>
      <el-main>
      <el-table size="small" :data="dataListOne" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column sortable prop="rid" label="序号" width="80">      
      </el-table-column>
      <el-table-column sortable prop="pname" label="患者姓名" width="100">
      </el-table-column>
      <el-table-column sortable prop="phoneNumber" label="联系方式" width="120">  
      </el-table-column>
      <el-table-column sortable prop="office" label="科室" width="80"> 
      </el-table-column>
      <el-table-column sortable prop="doctorName" label="接诊医生" width="100">        
      </el-table-column>
      <el-table-column sortable prop="registrationFee" label="挂号费（元）" width="120">      
      </el-table-column> 
      </el-table> 
      </el-main>
      <el-footer>
        <div >
          应收挂号费：{{dataListOne[0]===undefined?'':dataListOne[0].registrationFee}}元
        </div>
      </el-footer> 
      </el-container>
      <template>
          <el-button size="small" @click="closeDialog">取消</el-button>
          <el-button size="mini" type="danger" @click="updateReChargeStatus()">确认交费</el-button>
      </template>
      
    </el-dialog>
    <!-- 处方开立支付弹窗 -->
    <el-dialog title="处方开立费用支付" :visible.sync="detailVisable" width="621px" @click="closeDialog">
      <el-container>
      <el-main>
      <el-table size="small" :data="detailList" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">      
      <el-table-column sortable prop="id" label="处方项序号" width="120">
      </el-table-column>
      <el-table-column sortable prop="quantity" label="药品数量" width="100">
      </el-table-column>
      <el-table-column sortable prop="unit" label="单位" width="80">
      </el-table-column>
      <el-table-column sortable prop="commonName" label="药品名称" width="160">
      </el-table-column>
      <el-table-column sortable prop="price" label="单价" width="80">
        <template slot-scope="scope">
                <div>{{scope.row.price/100}}</div>
              </template>
      </el-table-column>

      </el-table>  
      </el-main>
      <el-footer>
        <div >
          应收处方开立费用：{{totalPrice/100}}元
        </div>
      </el-footer> 
      </el-container>
      <template>
          <el-button size="small" @click="closeDialog">取消</el-button>
          <el-button size="mini" type="danger" @click="updatePrChargeStatus()">确认交费</el-button>
      </template>
    </el-dialog>
    
  </div> 
</template>

<script>
import { reChargeType,prChargeType,chargeStatus } from '../../dict/chargeType'
import { deptList, deptSave, deptDelete } from '../../api/userMG'
import Pagination from '../../components/Pagination'
import axios from 'axios'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制弹窗显示与隐藏
      detailVisable:false,
      // editForm: {
      //   id:'',
      //   name:'',
      //   type:'', 
      //   selling:'',
      //   cost:'', 
      //   createTime:'',
      //   creator:'', 
      //   costType:'1111', 
      //   token: localStorage.getItem('logintoken')
      // },
      totalPrice:0,
      rid:0,
      //costClassType:costClassType,
      //rules表单验证
      rules: {
        deptName: [
          { required: true, message: '请输入部门名称', trigger: 'blur' }
        ],
        deptNo: [{ required: true, message: '请输入部门代码', trigger: 'blur' }]
      },
      formInline: {
        page: 1,
        limit: 10,
        pname:'',
        chargeStatus: '',
        // office:'',
        // doctor:'',
        // startDate:'',
        // endDate:'',
        token: localStorage.getItem('logintoken')
      },
      chargeStatus: chargeStatus,
      reChargeType:reChargeType,
      prChargeType:prChargeType,

      userparm: [], //搜索权限
      listData: [], //收费管理
      detailList:[], //处方项管理
      dataListOne:[],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },

  created() {
    this.getdata(this.formInline);
  
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods:  {
    // 
    getdata(parameter) {
      this.loading = true      
      axios.post('/api/chargeManagement/select/',{
        pageNum:1,
        pageSize:100,
        pid: this.$route.query.patientId,
        keywords:parameter.pname})
        .then(res => {
          this.loading = false     
          //console.log('结果是',res)     
          this.listData = res.data.data.list
          for(let item of this.listData){
              item.chargeStatusLabel=this.chargeStatus[item.chargeStatus]
              item.reChargeStatusLabel=this.reChargeType[item.reChargeStatus]
              item.prChargeStatusLabel=this.reChargeType[item.prChargeStatus]
          }
          // 分页赋值
          this.pageparm.currentPage = this.formInline.page
          this.pageparm.pageSize = this.formInline.limit
          this.pageparm.total = res.data.data.total          
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //查看收费情况
    lookUp(row){
       this.$router.push({
         path:'/workbench/patientInfo',
         query:{
           patientId:row.pid
         }      
       })
    },
    //展示挂号交费弹框
    rePayment(row){
        this.editFormVisible = true
        this.dataListOne=[]
        this.dataListOne.push(row)
        console.log("11111",this.dataListOne)
    },
    //展示处方开立交费弹框
    prPayment(row){
        this.rid=row.rid
        this.detailVisable = true
         this.loading = true      
         axios.get('/api/chargeManagement/selectOne/'+row.rid)
        .then(res => {
          this.loading = false     
          console.log('结果是',res)     
          this.detailList = res.data.data
          this.totalPrice=0;
          for(let i of this.detailList){
            this.totalPrice += i.totalPrice
          }
      
        })

    },
    //挂号交费提交按钮事件
    updateReChargeStatus(){
        axios.get('/api/chargeManagement/updateR/'+this.dataListOne[0].rid)
        .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.data.code==200) {
                this.$message({
                  type: 'success',
                  message: '交费成功！'                  
                })
                this.getdata(this.formInline);
              } else {
                this.$message({
                  type: 'info',
                  message: res.data.message
                })
              }
        })
    },
    //
    updatePrChargeStatus(){
        axios.get('/api/chargeManagement/updateP/'+this.rid)
          .then(res => {
                this.detailVisable = false
                this.loading = false
                if (res.data.code==200) {
                  this.$message({
                    type: 'success',
                    message: '交费成功！'                  
                  })
                  this.getdata(this.formInline);
                } else {
                  this.$message({
                    type: 'info',
                    message: res.data.message
                  })
                }
          }) 
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
      this.detailVisable = false
    },
    // 处方类型框改变后调用
    selectChange(){
      //console.log(this.formInline)
      this.getdata(this.formInline)      
    },
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.el-footer {
  background-color: rgb(34, 79, 148);
  color: rgb(255, 255, 255);
  text-align: right;
  line-height: 60px;
  
}

</style>